package com.lizhijun.controller;

import com.lizhijun.pojo.Employee;
import com.lizhijun.service.FinanceService;
import com.lizhijun.utils.LayuiTransform;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class FinanceController {

    @Autowired
    private FinanceService financeService;

    @RequestMapping("/fTable")
    @ResponseBody
    public LayuiTransform<Employee> findAll(){
        List<Employee> employeeList = financeService.findAll();
        LayuiTransform<Employee> layuiTransform = new LayuiTransform<>();
        layuiTransform.setData(employeeList);
        layuiTransform.setCode(0);
        layuiTransform.setCount(employeeList.size());
        layuiTransform.setMsg("success");
        return layuiTransform;
    }

    @RequestMapping("/updateBonusAndDeduction")
    @ResponseBody
    public void updateBonusAndDeduction(HttpServletRequest request){
        String eid = request.getParameter("eid");
        String s1 = request.getParameter("bonus");
        String s2 = request.getParameter("deduction");
        Integer bonus = Integer.parseInt(s1);
        Integer deduction = Integer.parseInt(s2);
        Employee employee = new Employee();
        employee.setEid(eid);
        employee.setBonus(bonus);
        employee.setDeduction(deduction);
        System.out.println(employee.getEid());
        System.out.println(employee.getBonus());
        System.out.println(employee.getDeduction());
        financeService.updateBonusAndDeduction(employee);
    }

}
